package com.liming.purchaseschema.webapp.wicket.page;

import com.liming.purchaseschema.api.biz.IPurchaseSchemaService;
import com.liming.purchaseschema.core.model.FixedFeeSchemaDefine;
import com.liming.purchaseschema.core.model.SchemaDefine;
import org.apache.aries.blueprint.annotation.Reference;
import org.apache.wicket.ajax.AjaxRequestTarget;
import org.apache.wicket.ajax.markup.html.AjaxLink;
import org.apache.wicket.ajax.markup.html.form.AjaxButton;
import org.apache.wicket.markup.html.basic.Label;
import org.apache.wicket.markup.html.form.DropDownChoice;
import org.apache.wicket.markup.html.form.Form;
import org.apache.wicket.markup.html.form.TextField;
import org.apache.wicket.markup.html.link.Link;
import org.apache.wicket.markup.html.panel.Panel;
import org.apache.wicket.markup.repeater.RepeatingView;
import org.apache.wicket.model.AbstractReadOnlyModel;
import org.apache.wicket.model.CompoundPropertyModel;
import org.apache.wicket.model.Model;
import org.apache.wicket.model.PropertyModel;

import javax.inject.Inject;
import javax.inject.Named;
import java.util.ArrayList;
import java.util.List;

/**
 * @类描述：
 * @创建人：wangkr
 * @创建时间：2014-04-14 上午9:13
 * @修改人：
 * @修改时间：
 * @修改备注：
 */

public class FixedFromPanel extends Panel {
    @Named
    @Inject
    @Reference(id = "purchaseSchemaService", serviceInterface = IPurchaseSchemaService.class)
    private IPurchaseSchemaService purchaseSchemaService;
    RepeatingView trialResult;
    public FixedFromPanel(String id, SchemaDefine schemaDefine, final SchemaDefine parentSchemaDefine,final TreePanel treePanel,final MyFormPanel formPanel) {
        super(id);
        final Form<SchemaDefine> form = new Form<SchemaDefine>("schemaDefineForm", new CompoundPropertyModel<SchemaDefine>(new SchemaDefine()));
        TextField name = new TextField("name");
        TextField desc = new TextField("desc");
        TextField fee = new TextField("fee");
        TextField formula = new TextField("formula");
        form.setModelObject(schemaDefine);
        form.add(name);
        form.add(desc);
        form.add(fee);
        form.add(formula);


        form.add(new AjaxButton("submit_button", form) {
            @Override
            protected void onSubmit(AjaxRequestTarget target, Form<?> submitForm) {
                SchemaDefine filledSalesmanBean = (SchemaDefine) getParent().getDefaultModelObject();
                if(null != parentSchemaDefine){
                    filledSalesmanBean.setParent(parentSchemaDefine.getId());
                }
                purchaseSchemaService.putSchemaDefine(filledSalesmanBean);
                treePanel.createTree(formPanel);
                target.add(treePanel);
            }

            @Override
            protected void onError(AjaxRequestTarget target, Form<?> form) {
                System.out.println("onError");
            }
        });
/*
        final Label label = new Label(trialResult.newChildId(),"");
        trialResult.add(label);

        AjaxLink ajaxLink = new AjaxLink("trial") {
            @Override
            public void onClick(AjaxRequestTarget ajaxRequestTarget) {
                label.
                ajaxRequestTarget.add(label);
            }
        };

        form.add(trialResult);
        form.add(ajaxLink);*/
        add(form);
    }
}


